<?php

class Check_key extends MySQL
{
    # 连接Mysql数据库
    function connect()
    {
        $conn = parent::connect();
        return $conn;
    }

    public function check_key()
    {
        if (is_array($_GET) && count($_GET) > 0) //判断是否有Get参数
        {
            //取得key
            $key = $_GET['key'];
            if (isset($_GET["key"])) //判断所需要的参数是否存在，isset用来检测变量是否设置，返回ID or false
            {
                $ID = parent::get_userId($key);
                return $ID;
            } else { // 不含有key
                $url = "../index.php";
                echo "<script type='text/javascript'>";
                echo "window.location.href='$url'";
                echo "</script>";
                exit;
            }
        } else {  //默认跳转,无token
            $url = "../index.php";
            echo "<script type='text/javascript'>";
            echo "window.location.href='$url'";
            echo "</script>";
            exit;
        }
    }
}
